<?php
$currency = Yii::app()->user->getState('currency');
$price = ObjectMeta::getPrice($data['object_id']);
$link = $data->getObjectLink();

$model = new FormBuynow();
$userId = Yii::app()->user->id;
?>
<div class="col">
    <h5>
        <?php
        echo CHtml::link($data['object_name'], array('page/render', 'slug' => $data['object_slug']), array('title' => $data['object_name']));
        ?>
    </h5>
    <p>
        <?php
        $imgUrl = (Resource::getFullPathByObjectID($data['object_id']) != '') ? Resource::getFullPathByObjectID($data['object_id']) : '';
        $image = '  <img height="70" width="120" class="' . $data['object_name'] . '" title="' . $data['object_name'] . '" alt="' . $data['object_name'] . '" src="' . $imgUrl . '">';
        //echo CHtml::link($image, $link, array('title' => $data['object_name']));
        echo CHtml::link($image, array('page/render', 'slug' => $data['object_slug']), array('class' => 'header-link'));
        ?>
    </p>
    <p><?php echo formatPrice($price) . ' ' . $currency; ?></p>
    <div class="views-field-addtocartlink">
        <?php
        $form = $this->beginWidget('CActiveForm', array(
            //'id'=>'main-content-form-'.$data['object_id'],
            'id' => 'list-view' . ConstantDefine::AJAX_BLOCK_SEPERATOR . $this->id . ConstantDefine::AJAX_BLOCK_SEPERATOR . $this->block['block_id'],
            //'enableAjaxValidation'=>false,
            'enableAjaxValidation' => TRUE,
            'enableClientValidation' => FALSE,
            'clientOptions' => array(
                'validateOnChange' => false,
                'validateOnSubmit' => true,
            ),
        ));
        echo $form->hiddenField($model, 'object_id', array('value' => $data['object_id']));
        ?>
        <div>
            <div class="form-item">
                SL: 
                <?php echo $form->textField($model, 'qty', array('value' => 1, 'size' => 3, 'maxlength' => 3, 'class' => 'inputText soluonght')); ?>
            </div>
            <?php
            if ($userId) {
                echo CHtml::submitButton('Add Cart', array('class' => 'buttonsubmit', 'name' => 'addcart'));
                /*
                  echo CHtml::ajaxSubmitButton(
                  'Add Cart',
                  array('site/addCart'),
                  array(
                  'success'=>'function(data){
                  var output= jQuery.parseJSON(data);
                  $("#cartContentTest").html(output);
                  alert(output.cart+" - "+output.cart);
                  $("#cartContent").html(output.cart);
                  $("#notifyMessage").removeAttr("style").html(output.mess);
                  $("html,body").animate({scrollTop:5},"slow");
                  $("#ajaxLoading").remove();
                  }',
                  'beforeSend'=>'function(){
                  $("#ajaxLoading").show();
                  }',
                  ),
                  array('class'=>'buttonsubmit'));
                 */
            }
            ?>
            <?= CHtml::submitButton('Buy Now', array('class' => 'buttonsubmit', 'name' => 'buynow')); ?>
        </div>
        <div id="cartContentTest"></div>
        <?php $this->endWidget(); ?>
    </div>
</div>
